home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UProjFileHandler.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  5.2 KB  |  265 lines  |  [TEXT/MPS ]

  1. // UProjFileHandler.cp
  2. // Copyright Â© 1984-1991 by Apple Computer Inc.    All rights reserved.
  3.  
  4.  
  5. #ifndef __ALIASES__
  6. #include <Aliases.h>
  7. #endif
  8.  
  9. #ifndef __UFILE__
  10. #include <UFile.h>
  11. #endif
  12.  
  13. #ifndef __EDITIONS__
  14. #include <Editions.h>
  15. #endif
  16.  
  17. #ifndef __APPLEEVENTS__
  18. #include <AppleEvents.h>
  19. #endif
  20.  
  21. #ifndef __ULIST__
  22. #include <UList.h>
  23. #endif
  24.  
  25. #ifndef __UEVENT__
  26. #include <UEvent.h>
  27. #endif
  28.  
  29. #ifndef __UCOMMAND__
  30. #include <UCommand.h>
  31. #endif
  32.  
  33. #ifndef __UEVTHANDLER__
  34. #include <UEvtHandler.h>
  35. #endif
  36.  
  37. #ifndef __DIALOGS__
  38. #include <Dialogs.h>
  39. #endif
  40.  
  41. #ifndef __UAPPLICATION__
  42. #include <UApplication.h>
  43. #endif
  44.  
  45. #ifndef __UDOCUMENT__
  46. #include <UDocument.h>
  47. #endif
  48.  
  49. #ifndef __UFILEBASEDDOCUMENT__
  50. #include <UFileBasedDocument.h>
  51. #endif
  52.  
  53. #ifndef __UFAILURE__
  54. #include <UFailure.h>
  55. #endif
  56.  
  57. #ifndef __QUICKDRAW__
  58. #include <QuickDraw.h>
  59. #endif
  60.  
  61. #ifndef __UMACAPPUTILITIES__
  62. #include <UMacAppUtilities.h>
  63. #endif
  64.  
  65. #ifndef __UERRORMGR__
  66. #include <UErrorMgr.h>
  67. #endif
  68.  
  69. #ifndef __UPATCH__
  70. #include <UPatch.h>
  71. #endif
  72.  
  73. #ifndef __UMACAPPGLOBALS__
  74. #include <UMacAppGlobals.h>
  75. #endif
  76.  
  77. #ifndef __RESOURCES__
  78. #include <Resources.h>
  79. #endif
  80.  
  81. #ifndef __TOOLUTILS__
  82. #include <ToolUtils.h>
  83. #endif
  84.  
  85. #ifndef __PACKAGES__
  86. #include <Packages.h>
  87. #endif
  88.  
  89. #ifndef __FOLDERS__
  90. #include <Folders.h>
  91. #endif
  92.  
  93. #ifndef __ERRORS__
  94. #include <Errors.h>
  95. #endif
  96.  
  97.  
  98. #ifndef __UPROJFILEHANDLER__
  99. #include <UProjFileHandler.h>
  100. #endif
  101.  
  102.  
  103. //--------------------------------------------------------------------------------------------------
  104. #pragma segment MAOpen
  105.  
  106. pascal void TProjFileHandler::Initialize(void)    // override
  107. {
  108.     inherited::Initialize();
  109.  
  110.     this->fProjStatus = notInProject;
  111.     this->fWriteckid = FALSE;
  112. }
  113.  
  114. //--------------------------------------------------------------------------------------------------
  115. #pragma segment MAFileRes
  116.  
  117. pascal void TProjFileHandler::IProjFileHandler(TFileBasedDocument* itsDocument,
  118.                                                TFile* itsFile,
  119.                                                const OSType itsFileType,
  120.                                                const OSType itsCreator,
  121.                                                Boolean usesDataFork,
  122.                                                Boolean usesRsrcFork,
  123.                                                Boolean keepsDataOpen,
  124.                                                Boolean keepsRsrcOpen)
  125.  
  126. {
  127.     this->IFileHandler(itsDocument, itsFile, itsFileType, itsCreator, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
  128. }
  129.  
  130. //--------------------------------------------------------------------------------------------------
  131. #pragma segment MAReadFile
  132.  
  133. pascal void TProjFileHandler::DoRead(Boolean forPrinting)// override 
  134. {
  135.     ProjectorHandle hProj;
  136.     short oldResFile;
  137.  
  138.     inherited::DoRead(forPrinting);
  139.  
  140.     if (this->fFile->IsRsrcForkOpen())
  141.     {
  142.         oldResFile = this->fFile->UseResource();
  143.         hProj = (ProjectorHandle) Get1Resource('ckid', 128);
  144.         if (hProj != NULL)
  145.         {
  146.             // found projector resource 
  147.             if ((*hProj)->checkoutState == 0)
  148.             {
  149.                 // checked out read only 
  150.                 if ((*hProj)->Modified == 0)
  151.                     this->fProjStatus = readOnly;// read only 
  152.                 else
  153.                     this->fProjStatus = modReadOnly;// modify/read only 
  154.             }
  155.             else
  156.                 this->fProjStatus = readWrite;    // checked out modifiable 
  157.         }
  158.         UseResFile(oldResFile);
  159.     }
  160. }
  161.  
  162. //--------------------------------------------------------------------------------------------------
  163. #pragma segment MAWriteFile
  164.  
  165. pascal void TProjFileHandler::DoWrite(TFile* aFile,
  166.                                       Boolean makingCopy)
  167. {
  168.     FailInfo fi;
  169.     Handle aHandle;
  170.     ProjectorHandle hProj;
  171.     long itsSize,
  172.      sum;
  173.     long* p;
  174.     short oldResFile;
  175.  
  176.     VOLATILE(aHandle);
  177.     VOLATILE(oldResFile);
  178.  
  179.     inherited::DoWrite(aFile, makingCopy);
  180.  
  181.     if (this->fWriteckid && aFile->IsRsrcForkOpen())
  182.     {
  183.         oldResFile = aFile->UseResource();
  184.  
  185.         if (fi.Try())
  186.         {
  187.             aHandle = Get1Resource('ckid', 128);
  188.             FailNILResource(aHandle);
  189.  
  190.             HNoPurge(aHandle);
  191.  
  192.             LoadResource(aHandle);
  193.             FailNILResource(aHandle);
  194.  
  195.             hProj = (ProjectorHandle) aHandle;
  196.  
  197.             (*hProj)->Modified = 1;                // modify/read only 
  198.  
  199.             // Recalculate the checksum so things look kosher… 
  200.             itsSize = (GetHandleSize((Handle)hProj) / sizeof(long)) - 1;
  201.             p = &(*hProj)->locationID;            // Skip the checksum field 
  202.             sum = 0;
  203.             while (itsSize > 0)
  204.             {
  205.                 sum = sum + *p++;
  206.                 --itsSize;
  207.             }
  208.  
  209.             (*hProj)->checksum = sum;
  210.  
  211.             aHandle = (Handle)hProj;
  212.  
  213.             ChangedResource(aHandle);
  214.             FailResError();
  215.  
  216.             WriteResource(aHandle);
  217.             FailResError();
  218.             fi.Success();
  219.         }
  220.         else    // Recover
  221.         {
  222.             HPurge(aHandle);
  223.             UseResFile(oldResFile);
  224.             fi.ReSignal();
  225.         }
  226.  
  227.         HPurge(aHandle);
  228.         UseResFile(oldResFile);
  229.     }
  230. }
  231.  
  232. //--------------------------------------------------------------------------------------------------
  233. #pragma segment MAFileRes
  234.  
  235. pascal ProjectorStatus TProjFileHandler::GetProjectorStatus(void)
  236. {
  237.     return this->fProjStatus;
  238. }
  239.  
  240. //--------------------------------------------------------------------------------------------------
  241. #pragma segment MAFileRes
  242.  
  243. pascal void TProjFileHandler::ModifyReadOnly(void)
  244. {
  245.     if (this->fProjStatus == readOnly)
  246.     {
  247.         fProjStatus = modReadOnly;
  248.         fWriteckid = TRUE;
  249.     }
  250. }
  251.  
  252. //--------------------------------------------------------------------------------------------------
  253. #pragma segment MAFields
  254.  
  255. pascal void TProjFileHandler::Fields(TObject* obj)
  256. {
  257.     obj->DoToField("TProjFileHandler", (Ptr)NULL, bClass);
  258.     obj->DoToField("fProjStatus", (Ptr) & fProjStatus, bByte);
  259.     obj->DoToField("fWriteckid", (Ptr) & fWriteckid, bBoolean);
  260.  
  261.     inherited::Fields(obj);
  262. }
  263.  
  264.  
  265.